﻿package view.effect
{
    import __AS3__.vec.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.utils.*;
    import morn.core.handlers.*;
    import morn.core.managers.*;

    public class ZoneParticle extends Sprite
    {
        private var _timeID:uint = 0;
        public static const STYLE_HORIZONTAL:int = 1;
        public static const STYLE_VERTICAL:int = 2;
        public static const VIEW_RANDOM:int = 1;

        public function ZoneParticle()
        {
            return;
        }// end function

        public function show(param1:int, param2:Object) : void
        {
            return;
        }// end function

        public function showOneParticle(param1:Object) : void
        {
            var _loc_2:String = "";
            var _loc_3:String = "";
            if (param1.icon)
            {
                var _loc_4:* = Config.getUrl("assets/images/particle/" + param1.icon + ".swf");
                param1.url = Config.getUrl("assets/images/particle/" + param1.icon + ".swf");
                _loc_2 = _loc_4;
                var _loc_4:* = Config.getUrl("assets/images/particle/" + param1.xml + ".xml");
                param1.xmlurl = Config.getUrl("assets/images/particle/" + param1.xml + ".xml");
                _loc_3 = _loc_4;
            }
            else if (param1.url)
            {
                _loc_2 = Config.getUrl(param1.url);
                _loc_3 = Config.getUrl(param1.xmlurl);
            }
            else
            {
                return;
            }
            App.mloader3.loadAssets([{url:_loc_2, type:ResLoader.SWF, size:100, priority:1}, {url:_loc_3, type:ResLoader.TXT, size:100, priority:1}], new Handler(this.oneComplete, [param1]));
            return;
        }// end function

        public function oneComplete(param1:Object) : void
        {
            var _loc_4:int = 0;
            var _loc_5:XMLMovieClip = null;
            var _loc_2:* = new XML(App.mloader3.getResLoaded(param1.xmlurl));
            var _loc_3:* = param1.showPos;
            switch(param1.style)
            {
                case STYLE_VERTICAL:
                {
                    _loc_4 = 0;
                    while (_loc_4 < _loc_3.length)
                    {
                        
                        _loc_5 = new XMLMovieClip("png.particle.fireworks", _loc_2);
                        this.addChild(_loc_5);
                        _loc_5.x = _loc_3[_loc_4];
                        _loc_5.y = _loc_3[(_loc_4 + 1)];
                        _loc_5.autoPlay = false;
                        _loc_5.playFromTo(0, (_loc_5.totalFrame - 1), new Handler(this.completeOne, [_loc_5, param1, 1]));
                        _loc_4 = _loc_4 + 2;
                    }
                    break;
                }
                case STYLE_HORIZONTAL:
                {
                    this.horizontalCheck(param1);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function horizontalCheck(param1:Object) : void
        {
            var _loc_2:* = param1.timeInterval;
            if (_loc_2.length <= 0)
            {
                return;
            }
            var _loc_3:* = _loc_2.shift();
            if (_loc_3 > 0)
            {
                if (this._timeID > 0)
                {
                    clearTimeout(this._timeID);
                    this._timeID = 0;
                }
                this._timeID = setTimeout(this.horizontalShow, _loc_3, param1, true);
            }
            else
            {
                this.horizontalShow(param1, false);
                this.horizontalCheck(param1);
            }
            return;
        }// end function

        public function horizontalShow(param1:Object, param2:Boolean) : void
        {
            if (this._timeID > 0)
            {
                clearTimeout(this._timeID);
                this._timeID = 0;
            }
            if (param2)
            {
                this.horizontalCheck(param1);
            }
            var _loc_3:* = param1.showPos;
            var _loc_4:* = new XML(App.mloader3.getResLoaded(param1.xmlurl));
            var _loc_5:* = new XMLMovieClip("png.particle.fireworks", _loc_4);
            this.addChild(_loc_5);
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            if (param1.viewType)
            {
                switch(param1.viewType)
                {
                    case VIEW_RANDOM:
                    {
                        _loc_6 = Math.random() * 200 - 100;
                        _loc_7 = Math.random() * 200 - 100;
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            _loc_5.x = _loc_3.shift() + _loc_6;
            _loc_5.y = _loc_3.shift() + _loc_7;
            _loc_5.autoPlay = false;
            _loc_5.playFromTo(0, (_loc_5.totalFrame - 1), new Handler(this.completeOne, [_loc_5, param1, 1]));
            return;
        }// end function

        private function completeOne(param1:XMLMovieClip, param2:Object, param3:int) : void
        {
            param1.stop();
            param3++;
            if (param2.times >= param3)
            {
                param1.playFromTo(0, (param1.totalFrame - 1), new Handler(this.completeOne, [param1, param2, param3]));
            }
            else
            {
                if (param1.parent)
                {
                    param1.parent.removeChild(param1);
                }
                param1.dispose();
                param1 = null;
            }
            return;
        }// end function

        public function clear() : void
        {
            return;
        }// end function

        public function clearArr() : void
        {
            return;
        }// end function

    }
}
